package com.wn.demo01;

import java.time.LocalDateTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author yellow Docter
 * @date 2024 -04-29
 * @desc
 *   基于线程池实现定时任务
 *       nacos的底层
 *          服务注册发现 的 监听基于 ScheduledExecutorService 来实现定时任务
 */
public class Demo02 {

    public static void main(String[] args) {

        //创建了一个线程池
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10);

        scheduler.scheduleAtFixedRate(()->{
            System.out.println("定时执行的任务：" + LocalDateTime.now());
        }, 5000, 2000, TimeUnit.MILLISECONDS);

    }

}
